package com.xx.happychatboot.middleware.netty.strategy.websocket;

import com.xx.happychatboot.middleware.netty.domain.enums.WebSocketTypeEnum;
import com.xx.happychatboot.middleware.netty.factory.websocket.WebSocketFactory;
import io.netty.channel.ChannelHandlerContext;

import javax.annotation.PostConstruct;

/**
 * 抽象websocket策略
 */
public abstract class AbstractWebsocketStrategy {
    @PostConstruct
    private void init() {
        //将策略类注册进工厂
        WebSocketFactory.register(getStrategyCode().getType(), this);
    }

    /**
     * 获取策略类型
     * @return
     */
    protected abstract WebSocketTypeEnum getStrategyCode();

    /**
     * 处理消息
     * @param channelHandlerContext
     * @param data
     */
    public abstract void execute(ChannelHandlerContext channelHandlerContext, String data);
}
